<?php
/**
 * CreateTime: 2022/6/1 14:00
 */

namespace App\Tools\DingTalk;

use App\Consts\DingTalkConsts\DingTalkConfigConsts;
use App\Func\AppFunc;
use App\Func\TokenFuc;
use OapiCallBackDeleteCallBackRequest;
use OapiCallBackRegisterCallBackRequest;

class DingTalkCallBackFacade extends BaseDingTalk
{
    /**
     * 注册回调
     * @return \$1|false|mixed|\ResultSet|\SimpleXMLElement
     */
    public static function registerCallBack(){
        $bestUrl = "https://oapi.dingtalk.com/call_back/register_call_back";
        $getCallBackRegisterRequest =  new OapiCallBackRegisterCallBackRequest();
        $getCallBackRegisterRequest->setCallBackTag("['bpms_task_change','bpms_instance_change']");
        $getCallBackRegisterRequest->setToken('zkVFMenQboXAG1exuKKygGLCWXLFmV2u1eKL5c');//加解密用的token
        $getCallBackRegisterRequest->setAesKey('w6pjxK7LznA2tma5juMBHDLUgUHJ6PkszAL1QyuVWpO');//aes_key 自行设置
        $getCallBackRegisterRequest->setUrl(AppFunc::getDingTalkConfig()::DING_CALL_BACK_TALK_URL);//回调的公网地址
//        dd(self::getDingTalkOldClient()->execute($getCallBackRegisterRequest, self::getAccessToken(),$bestUrl));
        return self::getDingTalkOldClient()->execute($getCallBackRegisterRequest, self::getAccessToken(),$bestUrl);
    }

    /**
     * 删除回调
     * @return \$1|false|mixed|\ResultSet|\SimpleXMLElement
     */
    public static function deleteRegisterCallBack(){
        $bestUrl = "https://oapi.dingtalk.com/call_back/delete_call_back";
        $apiCallBackDeleteCallBackRequest = new OapiCallBackDeleteCallBackRequest();
        return self::getDingTalkOldClient()->execute($apiCallBackDeleteCallBackRequest, self::getAccessToken(),$bestUrl);
    }
}